package jiang.SensitiveWord;

import java.io.*;
import java.util.*;

import static jiang.SensitiveWord.SensitiveWordUtil.*;

/**
 * @ClassName GetSensitiveWords
 * @Description:
 * @Author jiangshitao
 * @Date 2023/11/2
 */
public class CheckSensitiveWords {

    static Map<Object,Object> sensitiveWordsMap;

    private static String encoding = "UTF-8";

    static final String END_FLAG="end";

    public static void main(String[] args) throws Exception {
        Set<String> sensitiveWords=new HashSet<>();

        File file = new File(CheckSensitiveWords.class.getResource("/filter/keyword.txt").getPath());
        FileInputStream fileInputStream = new FileInputStream(file);
        InputStreamReader read = new InputStreamReader(fileInputStream, encoding);
        BufferedReader bufferedReader = new BufferedReader(read);
        String txt = null;

        while((txt = bufferedReader.readLine()) != null) {
            sensitiveWords.add(txt);
        }
        fileInputStream.close();
        bufferedReader.close();
        read.close();

        long a = System.currentTimeMillis();
        initSensitiveWordsMap(sensitiveWords);
        String text="你你你你是傻逼啊你，说你呢，你个大笨蛋。";
        long b = System.currentTimeMillis();
        System.out.println(b - a);
        System.out.println(SensitiveWordUtil.getSensitiveWords(text,"最大匹配规则"));

        // 上面方法的效率大致为下面方法的十倍
        long c = System.currentTimeMillis();
        Set<String> strings = checkSensitiveWord(text);
        long d = System.currentTimeMillis();
        System.out.println(d - c);
        System.out.println(KeywordUtil.getKeywordString(strings));

    }


}
